﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IndoReputation.Models.BusinessObject;
using IndoReputation.Models.BusinessObject.Collections;
using IndoReputation.Models.DataAccess;

namespace IndoReputation.Models.BusinessLogic
{
    public class OfficeBOL
    {
        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 4/22/2012  6:03 PM
        /// Todo: Insert an office to db
        /// </summary>
        /// <param name="office">The office.</param>
        /// <returns></returns>
        public static int Insert(Office office)
        {
            try
            {
                office.CreateAt = DateTime.Now;
                office.CreateBy = MySession.UserID;
                office.UpdateAt = null;
                office.UpdateBy = null;
                return OfficeDAL.Insert(office);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  9:45 AM
        /// Todo: Update a User Exists in Database 
        /// </summary>
        /// <param name="office">A office.</param>
        /// <returns></returns>
        public static bool Update(Office office)
        {
            try
            {
                office.UpdateAt = DateTime.Now;
                office.UpdateBy = MySession.UserID;
                return OfficeDAL.Update(office);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  10:36 AM
        /// Todo: Delete a User Existst in Database
        /// </summary>
        /// <param name="office">A office.</param>
        /// <returns></returns>
        public static bool Delete(int officeID)
        {
            try
            {
                return OfficeDAL.Delete(officeID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/29/2011  5:23 PM
        /// Todo: Get All Office
        /// </summary>
        /// <returns></returns>
        public static OfficeList GetAllOffice()
        {
            try
            {
                return OfficeDAL.GetAllOffice() ?? new OfficeList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        /// <summary>
        /// Author: Nguyen Duc Thanh Tung
        /// Created on: 11/30/2011  10:40 AM
        /// Todo: Select a User existst in Database
        /// </summary>
        /// <param name="officeID">The office ID.</param>
        /// <returns></returns>
        public static Office GetOfficeById(int officeID)
        {
            try
            {
                return OfficeDAL.GetOfficeById(officeID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        public static OfficeJoinGroup GetOfficeJoinGroupById(int officeID)
        {
            try
            {
                return OfficeDAL.GetOfficeJoinGroupById(officeID);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        public static OfficeJoinList GetAllOfficeJoin()
        {
            try
            {
                return OfficeDAL.GetAllOfficeJoin() ?? new OfficeJoinList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }

        public static OfficeList GetAllOfficeByCountry(int countryID)
        {
            try
            {
                return OfficeDAL.GetAllOfficeByCountry(countryID) ?? new OfficeList();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
    }
}